import sys, os
sys.path.append(os.getcwd())

from selenium.webdriver.common.by import By

from base.base_action import BaseAction


class AnnouncePage(BaseAction):
    # 公告页面

    """
    contexts = driver.contexts
        for i in contexts:
        print(i)

        driver.switch_to.context("WEBVIEW_com.chebao")

    """

    # 平台公告 id = com.chebao:id/day_text
    companyann_button = By.ID, "com.chebao:id/day_text"

    # 媒体报道 id = com.chebao:id/month_text
    media_button = By.ID, "com.chebao:id/month_text"

    # 第一条公告 xpath //*[contains(@instance,'6')]
    firstann_button = By.XPATH, "//*[contains(@instance,'6')]"

    # 平台公告列表 xpath "//android.support.v7.widget.RecyclerView/android.widget.FrameLayout"
    ann_list_elm = By.XPATH, "//android.support.v7.widget.RecyclerView/android.widget.FrameLayout"
    # ann_list_elm = By.XPATH, "//android.support.v7.widget.RecyclerView/android.widget.FrameLayout"

    # 返回 class = android.widget.RelativeLayout
    return_button = By.CLASS_NAME, "android.widget.ImageView"

    def __init__(self, driver):
        BaseAction.__init__(self, driver)

    def click_companyann(self):
        # 点击平台公告
        return self.act_click(self.companyann_button)

    def click_media(self):
        # 点击媒体报道
        return self.act_click(self.media_button)

    def click_companyann_details(self):
        # 查看公告详情
        announce_list = self.find_elements(self.ann_list_elm)   # 获取所有公告
        for i in announce_list:
            print(i)
            i.click()  # 点击公告列表信息，查看公告详情
            self.act_click(self.return_button)   # 点击返回，公平页面
        self.act_click(self.return_button)

    def click_return(self):
        # 点击返回按钮
        return self.act_click(self.return_button)





